package com.gryffonx.Interfaces.NPC;

import com.gryffonx.DiceRoller.StaticDiceRoller;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;

/**
 * **************************************************************************
 * Application:
 * Author: Erik Stell
 * Date: Feb 22, 2005
 * Time: 9:29:36 AM
 * Process:
 * **************************************************************************
 */
public class NPCEditBinding {
    private JPanel pnl_MainPanel;
    private JPanel pnl_IconsItems;
    private JPanel pnl_Disposal;
    private JButton btn_Cancel;
    private JButton btn_OK;
    private JPanel pnl_Options;
    private JCheckBox chk_DisableTalk;
    private JLabel lbl_ExamineLabel;
    private JTextField txt_ExamineLabel;
    private JLabel lbl_ExamineEvent;
    private JButton btn_ExamineEvent;
    private JTextField txt_TalkLabel;
    private JButton btn_TalkEvent;
    private JButton btn_CombatIcon;
    private JButton btn_SmallPic;
    private JLabel lbl_TalkLabel;
    private JLabel lbl_TalkEvent;
    private JLabel lbl_CombatIcon;
    private JLabel lbl_SmallPic;
    private JButton btn_Items;
    private JButton btn_Spells;
    private JButton btn_Money;
    private JPanel pnl_Character;
    private JPanel pnl_Traits;
    private JPanel pnl_Levels;
    private JTextField txt_Experience3;
    private JLabel lbl_Levels3;
    private JLabel lbl_Levels2;
    private JLabel lbl_Levels1;
    private JTextField txt_Experience2;
    private JLabel lbl_Levels;
    private JLabel lbl_ExperiencePoints;
    private JTextField txt_Experience1;
    private JPanel pnl_CharTraits;
    private JPanel pnl_HPAge;
    private JLabel lbl_HitPoints;
    private JLabel lbl_Age;
    private JLabel lbl_Race;
    private JLabel lbl_Alignment;
    private JLabel lbl_Gender;
    private JComboBox cbo_Gender;
    private JComboBox cbo_Align;
    private JComboBox cbo_Race;
    private JComboBox cbo_Class;
    private JLabel lbl_Name;
    private JLabel lbl_Class;
    private JTextField txt_Name;
    private JPanel pnl_StatsOpts;
    private JPanel pnl_SystemOpts;
    private JCheckBox chk_CanBeSaved;
    private JCheckBox chk_CanTradeItems;
    private JCheckBox chk_PreGen;
    private JPanel pnl_Stats;
    private JButton btn_Roll;
    private JPanel pnl_Skills;
    private JTextField txt_StrMod;
    private JLabel lbl_Charisma;
    private JLabel lbl_Wisdom;
    private JLabel lbl_Intelligence;
    private JLabel lbl_Constitution;
    private JLabel lbl_Dexterity;
    private JLabel lbl_Strength;
    private JSpinner txt_hitPoints;
    private JSpinner spnr_Age;
    private JSpinner spnr_levels1;
    private JSpinner spnr_levels2;
    private JSpinner spnr_levels3;
    private JTextField txtStrMod;
    private JTextField txtDexMod;
    private JTextField txtChaMod;
    private JTextField txtWisMod;
    private JTextField txtIntMod;
    private JTextField txtConMod;
    private JSpinner spnr_Cha;
    private JSpinner spnr_Wis;
    private JSpinner spnr_Int;
    private JSpinner spnr_Con;
    private JSpinner spnr_Dex;
    private JSpinner spnr_Str;

    public JPanel getPnl_MainPanel() {
        return pnl_MainPanel;
    }

    public void setPnl_MainPanel(JPanel pnl_MainPanel) {
        this.pnl_MainPanel = pnl_MainPanel;
    }

    public JPanel getPnl_IconsItems() {
        return pnl_IconsItems;
    }

    public void setPnl_IconsItems(JPanel pnl_IconsItems) {
        this.pnl_IconsItems = pnl_IconsItems;
    }

    public JPanel getPnl_Disposal() {
        return pnl_Disposal;
    }

    public void setPnl_Disposal(JPanel pnl_Disposal) {
        this.pnl_Disposal = pnl_Disposal;
    }

    public JButton getBtn_Cancel() {
        return btn_Cancel;
    }

    public void setBtn_Cancel(JButton btn_Cancel) {
        this.btn_Cancel = btn_Cancel;
    }

    public JButton getBtn_OK() {
        return btn_OK;
    }

    public void setBtn_OK(JButton btn_OK) {
        this.btn_OK = btn_OK;
    }

    public JPanel getPnl_Options() {
        return pnl_Options;
    }

    public void setPnl_Options(JPanel pnl_Options) {
        this.pnl_Options = pnl_Options;
    }

    public JCheckBox getChk_DisableTalk() {
        return chk_DisableTalk;
    }

    public void setChk_DisableTalk(JCheckBox chk_DisableTalk) {
        this.chk_DisableTalk = chk_DisableTalk;
    }

    public JLabel getLbl_ExamineLabel() {
        return lbl_ExamineLabel;
    }

    public void setLbl_ExamineLabel(JLabel lbl_ExamineLabel) {
        this.lbl_ExamineLabel = lbl_ExamineLabel;
    }

    public JTextField getTxt_ExamineLabel() {
        return txt_ExamineLabel;
    }

    public void setTxt_ExamineLabel(JTextField txt_ExamineLabel) {
        this.txt_ExamineLabel = txt_ExamineLabel;
    }

    public JLabel getLbl_ExamineEvent() {
        return lbl_ExamineEvent;
    }

    public void setLbl_ExamineEvent(JLabel lbl_ExamineEvent) {
        this.lbl_ExamineEvent = lbl_ExamineEvent;
    }

    public JButton getBtn_ExamineEvent() {
        return btn_ExamineEvent;
    }

    public void setBtn_ExamineEvent(JButton btn_ExamineEvent) {
        this.btn_ExamineEvent = btn_ExamineEvent;
    }

    public JTextField getTxt_TalkLabel() {
        return txt_TalkLabel;
    }

    public void setTxt_TalkLabel(JTextField txt_TalkLabel) {
        this.txt_TalkLabel = txt_TalkLabel;
    }

    public JButton getBtn_TalkEvent() {
        return btn_TalkEvent;
    }

    public void setBtn_TalkEvent(JButton btn_TalkEvent) {
        this.btn_TalkEvent = btn_TalkEvent;
    }

    public JButton getBtn_CombatIcon() {
        return btn_CombatIcon;
    }

    public void setBtn_CombatIcon(JButton btn_CombatIcon) {
        this.btn_CombatIcon = btn_CombatIcon;
    }

    public JButton getBtn_SmallPic() {
        return btn_SmallPic;
    }

    public void setBtn_SmallPic(JButton btn_SmallPic) {
        this.btn_SmallPic = btn_SmallPic;
    }

    public JLabel getLbl_TalkLabel() {
        return lbl_TalkLabel;
    }

    public void setLbl_TalkLabel(JLabel lbl_TalkLabel) {
        this.lbl_TalkLabel = lbl_TalkLabel;
    }

    public JLabel getLbl_TalkEvent() {
        return lbl_TalkEvent;
    }

    public void setLbl_TalkEvent(JLabel lbl_TalkEvent) {
        this.lbl_TalkEvent = lbl_TalkEvent;
    }

    public JLabel getLbl_CombatIcon() {
        return lbl_CombatIcon;
    }

    public void setLbl_CombatIcon(JLabel lbl_CombatIcon) {
        this.lbl_CombatIcon = lbl_CombatIcon;
    }

    public JLabel getLbl_SmallPic() {
        return lbl_SmallPic;
    }

    public void setLbl_SmallPic(JLabel lbl_SmallPic) {
        this.lbl_SmallPic = lbl_SmallPic;
    }

    public JButton getBtn_Items() {
        return btn_Items;
    }

    public void setBtn_Items(JButton btn_Items) {
        this.btn_Items = btn_Items;
    }

    public JButton getBtn_Spells() {
        return btn_Spells;
    }

    public void setBtn_Spells(JButton btn_Spells) {
        this.btn_Spells = btn_Spells;
    }

    public JButton getBtn_Money() {
        return btn_Money;
    }

    public void setBtn_Money(JButton btn_Money) {
        this.btn_Money = btn_Money;
    }

    public JPanel getPnl_Character() {
        return pnl_Character;
    }

    public void setPnl_Character(JPanel pnl_Character) {
        this.pnl_Character = pnl_Character;
    }

    public JPanel getPnl_Traits() {
        return pnl_Traits;
    }

    public void setPnl_Traits(JPanel pnl_Traits) {
        this.pnl_Traits = pnl_Traits;
    }

    public JPanel getPnl_Levels() {
        return pnl_Levels;
    }

    public void setPnl_Levels(JPanel pnl_Levels) {
        this.pnl_Levels = pnl_Levels;
    }

    public JTextField getTxt_Experience3() {
        return txt_Experience3;
    }

    public void setTxt_Experience3(JTextField txt_Experience3) {
        this.txt_Experience3 = txt_Experience3;
    }

    public JLabel getLbl_Levels3() {
        return lbl_Levels3;
    }

    public void setLbl_Levels3(JLabel lbl_Levels3) {
        this.lbl_Levels3 = lbl_Levels3;
    }

    public JLabel getLbl_Levels2() {
        return lbl_Levels2;
    }

    public void setLbl_Levels2(JLabel lbl_Levels2) {
        this.lbl_Levels2 = lbl_Levels2;
    }

    public JLabel getLbl_Levels1() {
        return lbl_Levels1;
    }

    public void setLbl_Levels1(JLabel lbl_Levels1) {
        this.lbl_Levels1 = lbl_Levels1;
    }

    public JTextField getTxt_Experience2() {
        return txt_Experience2;
    }

    public void setTxt_Experience2(JTextField txt_Experience2) {
        this.txt_Experience2 = txt_Experience2;
    }


    public JLabel getLbl_Levels() {
        return lbl_Levels;
    }

    public void setLbl_Levels(JLabel lbl_Levels) {
        this.lbl_Levels = lbl_Levels;
    }

    public JLabel getLbl_ExperiencePoints() {
        return lbl_ExperiencePoints;
    }

    public void setLbl_ExperiencePoints(JLabel lbl_ExperiencePoints) {
        this.lbl_ExperiencePoints = lbl_ExperiencePoints;
    }

    public JTextField getTxt_Experience1() {
        return txt_Experience1;
    }

    public void setTxt_Experience1(JTextField txt_Experience1) {
        this.txt_Experience1 = txt_Experience1;
    }

    public JPanel getPnl_CharTraits() {
        return pnl_CharTraits;
    }

    public void setPnl_CharTraits(JPanel pnl_CharTraits) {
        this.pnl_CharTraits = pnl_CharTraits;
    }

    public JPanel getPnl_HPAge() {
        return pnl_HPAge;
    }

    public void setPnl_HPAge(JPanel pnl_HPAge) {
        this.pnl_HPAge = pnl_HPAge;
    }

    public JLabel getLbl_HitPoints() {
        return lbl_HitPoints;
    }

    public void setLbl_HitPoints(JLabel lbl_HitPoints) {
        this.lbl_HitPoints = lbl_HitPoints;
    }

    public JLabel getLbl_Age() {
        return lbl_Age;
    }

    public void setLbl_Age(JLabel lbl_Age) {
        this.lbl_Age = lbl_Age;
    }

    public JLabel getLbl_Race() {
        return lbl_Race;
    }

    public void setLbl_Race(JLabel lbl_Race) {
        this.lbl_Race = lbl_Race;
    }

    public JLabel getLbl_Alignment() {
        return lbl_Alignment;
    }

    public void setLbl_Alignment(JLabel lbl_Alignment) {
        this.lbl_Alignment = lbl_Alignment;
    }

    public JLabel getLbl_Gender() {
        return lbl_Gender;
    }

    public void setLbl_Gender(JLabel lbl_Gender) {
        this.lbl_Gender = lbl_Gender;
    }

    public JComboBox getCbo_Gender() {
        return cbo_Gender;
    }

    public void setCbo_Gender(JComboBox cbo_Gender) {
        this.cbo_Gender = cbo_Gender;
    }

    public JComboBox getCbo_Align() {
        return cbo_Align;
    }

    public void setCbo_Align(JComboBox cbo_Align) {
        this.cbo_Align = cbo_Align;
    }

    public JComboBox getCbo_Race() {
        return cbo_Race;
    }

    public void setCbo_Race(JComboBox cbo_Race) {
        this.cbo_Race = cbo_Race;
    }

    public JComboBox getCbo_Class() {
        return cbo_Class;
    }

    public void setCbo_Class(JComboBox cbo_Class) {
        this.cbo_Class = cbo_Class;
    }

    public JLabel getLbl_Name() {
        return lbl_Name;
    }

    public void setLbl_Name(JLabel lbl_Name) {
        this.lbl_Name = lbl_Name;
    }

    public JLabel getLbl_Class() {
        return lbl_Class;
    }

    public void setLbl_Class(JLabel lbl_Class) {
        this.lbl_Class = lbl_Class;
    }

    public JTextField getTxt_Name() {
        return txt_Name;
    }

    public void setTxt_Name(JTextField txt_Name) {
        this.txt_Name = txt_Name;
    }

    public JPanel getPnl_StatsOpts() {
        return pnl_StatsOpts;
    }

    public void setPnl_StatsOpts(JPanel pnl_StatsOpts) {
        this.pnl_StatsOpts = pnl_StatsOpts;
    }

    public JPanel getPnl_SystemOpts() {
        return pnl_SystemOpts;
    }

    public void setPnl_SystemOpts(JPanel pnl_SystemOpts) {
        this.pnl_SystemOpts = pnl_SystemOpts;
    }

    public JCheckBox getChk_CanBeSaved() {
        return chk_CanBeSaved;
    }

    public void setChk_CanBeSaved(JCheckBox chk_CanBeSaved) {
        this.chk_CanBeSaved = chk_CanBeSaved;
    }

    public JCheckBox getChk_CanTradeItems() {
        return chk_CanTradeItems;
    }

    public void setChk_CanTradeItems(JCheckBox chk_CanTradeItems) {
        this.chk_CanTradeItems = chk_CanTradeItems;
    }

    public JCheckBox getChk_PreGen() {
        return chk_PreGen;
    }

    public void setChk_PreGen(JCheckBox chk_PreGen) {
        this.chk_PreGen = chk_PreGen;
    }

    public JPanel getPnl_Stats() {
        return pnl_Stats;
    }

    public void setPnl_Stats(JPanel pnl_Stats) {
        this.pnl_Stats = pnl_Stats;
    }

    public JButton getBtn_Roll() {
        return btn_Roll;
    }

    public void setBtn_Roll(JButton btn_Roll) {
        this.btn_Roll = btn_Roll;
    }

    public JPanel getPnl_Skills() {
        return pnl_Skills;
    }

    public void setPnl_Skills(JPanel pnl_Skills) {
        this.pnl_Skills = pnl_Skills;
    }

    public JTextField getTxt_StrMod() {
        return txt_StrMod;
    }

    public void setTxt_StrMod(JTextField txt_StrMod) {
        this.txt_StrMod = txt_StrMod;
    }

    public JLabel getLbl_Charisma() {
        return lbl_Charisma;
    }

    public void setLbl_Charisma(JLabel lbl_Charisma) {
        this.lbl_Charisma = lbl_Charisma;
    }

    public JLabel getLbl_Wisdom() {
        return lbl_Wisdom;
    }

    public void setLbl_Wisdom(JLabel lbl_Wisdom) {
        this.lbl_Wisdom = lbl_Wisdom;
    }

    public JLabel getLbl_Intelligence() {
        return lbl_Intelligence;
    }

    public void setLbl_Intelligence(JLabel lbl_Intelligence) {
        this.lbl_Intelligence = lbl_Intelligence;
    }

    public JLabel getLbl_Constitution() {
        return lbl_Constitution;
    }

    public void setLbl_Constitution(JLabel lbl_Constitution) {
        this.lbl_Constitution = lbl_Constitution;
    }

    public JLabel getLbl_Dexterity() {
        return lbl_Dexterity;
    }

    public void setLbl_Dexterity(JLabel lbl_Dexterity) {
        this.lbl_Dexterity = lbl_Dexterity;
    }

    public JLabel getLbl_Strength() {
        return lbl_Strength;
    }

    public void setLbl_Strength(JLabel lbl_Strength) {
        this.lbl_Strength = lbl_Strength;
    }

    public NPCEditBinding() {
        this.cbo_Gender.addItem("Male");
        this.cbo_Gender.addItem("Female");

        this.cbo_Align.addItem("Lawful Good");
        this.cbo_Align.addItem("Chaotic Good");
        this.cbo_Align.addItem("Neutral Good");
        this.cbo_Align.addItem("Lawful Neutral");
        this.cbo_Align.addItem("True Neutral");
        this.cbo_Align.addItem("Chaotic Neutral");
        this.cbo_Align.addItem("Lawful Evil");
        this.cbo_Align.addItem("Neutral Evil");
        this.cbo_Align.addItem("Chaotic Evil");

        this.cbo_Race.addItem("Human");
        this.cbo_Race.addItem("Elf");
        this.cbo_Race.addItem("Half-Elf");
        this.cbo_Race.addItem("Dwarf");
        this.cbo_Race.addItem("Gnome");
        this.cbo_Race.addItem("Halfling");

        this.cbo_Class.addItem("Fighter");
        this.cbo_Class.addItem("Priest");
        this.cbo_Class.addItem("Rogue");
        this.cbo_Class.addItem("Sorcerer");
        this.cbo_Class.addItem("Mage");
        this.cbo_Class.addItem("Druid");
        this.cbo_Class.addItem("Ranger");


        this.cbo_Class.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                lbl_Levels1.setText(cbo_Class.getSelectedItem().toString());

                if (cbo_Class.getSelectedItem().toString().equals("Sorcerer")
                        || cbo_Class.getSelectedItem().toString().equals("Priest")
                        || cbo_Class.getSelectedItem().toString().equals("Druid")
                        || cbo_Class.getSelectedItem().toString().equals("Ranger")
                        || cbo_Class.getSelectedItem().toString().equals("Mage")) {
                    btn_Spells.setEnabled(true);
                } else {
                    btn_Spells.setEnabled(false);
                }
            }
        });

        this.btn_Roll.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                rollStatsAndMods();
            }
        });


        this.spnr_Str.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                calculateMod(spnr_Str, txtStrMod);
            }
        });
        this.spnr_Dex.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                calculateMod(spnr_Dex, txtDexMod);
            }
        });
        this.spnr_Con.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                calculateMod(spnr_Con, txtConMod);
            }
        });
        this.spnr_Int.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                calculateMod(spnr_Int, txtIntMod);
            }
        });
        this.spnr_Wis.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                calculateMod(spnr_Wis, txtWisMod);
            }
        });
        this.spnr_Cha.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                calculateMod(spnr_Cha, txtChaMod);
            }
        });

        this.spnr_levels1.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                String spnrValue = spnr_levels1.getValue().toString();
                Integer spnrIntValue = new Integer(spnrValue);

                if (spnrIntValue < 0) {
                    spnr_levels1.setValue(new Integer("0"));
                }

                if (spnrIntValue >= 20) {
                    spnr_levels1.setValue(new Integer("20"));
                }

                if (spnrIntValue == 0) {
                    txt_Experience1.setText("0");
                } else if (spnrIntValue == 1) {
                    txt_Experience1.setText("1000");
                } else if (spnrIntValue == 2) {
                    txt_Experience1.setText("2000");
                } else if (spnrIntValue == 3) {
                    txt_Experience1.setText("3000");
                } else if (spnrIntValue == 4) {
                    txt_Experience1.setText("4000");
                } else if (spnrIntValue == 5) {
                    txt_Experience1.setText("5000");
                } else if (spnrIntValue == 6) {
                    txt_Experience1.setText("6000");
                } else if (spnrIntValue == 7) {
                    txt_Experience1.setText("7000");
                } else if (spnrIntValue == 8) {
                    txt_Experience1.setText("8000");
                } else if (spnrIntValue == 9) {
                    txt_Experience1.setText("9000");
                } else if (spnrIntValue == 10) {
                    txt_Experience1.setText("10000");
                } else if (spnrIntValue == 11) {
                    txt_Experience1.setText("11000");
                } else if (spnrIntValue == 12) {
                    txt_Experience1.setText("12000");
                } else if (spnrIntValue == 13) {
                    txt_Experience1.setText("13000");
                } else if (spnrIntValue == 14) {
                    txt_Experience1.setText("14000");
                } else if (spnrIntValue == 15) {
                    txt_Experience1.setText("15000");
                } else if (spnrIntValue == 16) {
                    txt_Experience1.setText("16000");
                } else if (spnrIntValue == 17) {
                    txt_Experience1.setText("17000");
                } else if (spnrIntValue == 18) {
                    txt_Experience1.setText("18000");
                } else if (spnrIntValue == 19) {
                    txt_Experience1.setText("19000");
                } else if (spnrIntValue == 20) {
                    txt_Experience1.setText("20000");
                }
            }
        });

        this.txt_Experience1.addFocusListener(new FocusListener() {
            public void focusGained(FocusEvent evt) {

            }

            public void focusLost(FocusEvent evt) {
                String expVal = txt_Experience1.getText();
                Integer expValInt = new Integer(expVal);

                if (expValInt == null) {
                    expValInt = 0;
                }
                if (expValInt <= 0) {
                    txt_Experience1.setText(expValInt.toString());
                }


                if (expValInt <= 1000) {
                    spnr_levels1.setValue(0);
                } else if (expValInt > 1000 && expValInt <= 2000) {
                    spnr_levels1.setValue(1);
                } else if (expValInt > 2000 && expValInt <= 3000) {
                    spnr_levels1.setValue(2);
                } else if (expValInt > 3000 && expValInt <= 4000) {
                    spnr_levels1.setValue(3);
                } else if (expValInt > 4000 && expValInt <= 5000) {
                    spnr_levels1.setValue(4);
                } else if (expValInt > 5000 && expValInt <= 6000) {
                    spnr_levels1.setValue(5);
                } else if (expValInt > 6000 && expValInt <= 7000) {
                    spnr_levels1.setValue(6);
                } else if (expValInt > 7000 && expValInt <= 8000) {
                    spnr_levels1.setValue(7);
                } else if (expValInt > 8000 && expValInt <= 9000) {
                    spnr_levels1.setValue(8);
                } else if (expValInt > 9000 && expValInt <= 10000) {
                    spnr_levels1.setValue(9);
                } else if (expValInt > 10000 && expValInt <= 11000) {
                    spnr_levels1.setValue(10);
                } else if (expValInt > 11000 && expValInt <= 12000) {
                    spnr_levels1.setValue(11);
                } else if (expValInt > 12000 && expValInt <= 13000) {
                    spnr_levels1.setValue(12);
                } else if (expValInt > 13000 && expValInt <= 14000) {
                    spnr_levels1.setValue(13);
                } else if (expValInt > 14000 && expValInt <= 15000) {
                    spnr_levels1.setValue(14);
                } else if (expValInt > 15000 && expValInt <= 16000) {
                    spnr_levels1.setValue(15);
                } else if (expValInt > 16000 && expValInt <= 17000) {
                    spnr_levels1.setValue(16);
                } else if (expValInt > 17000 && expValInt <= 18000) {
                    spnr_levels1.setValue(17);
                } else if (expValInt > 18000 && expValInt <= 19000) {
                    spnr_levels1.setValue(18);
                } else if (expValInt > 19000 && expValInt <= 20000) {
                    spnr_levels1.setValue(19);
                } else if (expValInt >= 20000) {
                    spnr_levels1.setValue(20);
                }

            }
        });

        this.btn_Money.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                NPCMoney window = new NPCMoney("Enter Quantity");
                window.pack();
                window.setVisible(true);

            }
        });

        this.btn_Spells.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                SpellList window = new SpellList("Choose Spells");
                window.pack();
                window.setVisible(true);

            }
        });


    }

    private void rollStatsAndMods() {
        spnr_Str.setValue(StaticDiceRoller.rolldStat(6, 4));
        if (spnr_Str.getValue().toString().equals("18")) {
            txt_StrMod.setText(Integer.toString(StaticDiceRoller.rolldStat(6, 4)));
        } else {
            txt_StrMod.setText("");
        }

        spnr_Dex.setValue(StaticDiceRoller.rolldStat(6, 4));
        spnr_Con.setValue(StaticDiceRoller.rolldStat(6, 4));
        spnr_Int.setValue(StaticDiceRoller.rolldStat(6, 4));
        spnr_Wis.setValue(StaticDiceRoller.rolldStat(6, 4));
        spnr_Cha.setValue(StaticDiceRoller.rolldStat(6, 4));

        if (cbo_Race.getSelectedItem().toString().equals("Elf")) {
            spnr_Dex.setValue(Integer.parseInt(spnr_Dex.getValue().toString()) + 2);
            spnr_Con.setValue(Integer.parseInt(spnr_Con.getValue().toString()) - 2);

        }
        if (cbo_Race.getSelectedItem().toString().equals("Dwarf")) {
            spnr_Cha.setValue(Integer.parseInt(spnr_Cha.getValue().toString()) + 2);
            spnr_Con.setValue(Integer.parseInt(spnr_Con.getValue().toString()) + 2);

        }
        if (cbo_Race.getSelectedItem().toString().equals("Halfling")) {
            spnr_Dex.setValue(Integer.parseInt(spnr_Dex.getValue().toString()) + 2);
            spnr_Str.setValue(Integer.parseInt(spnr_Str.getValue().toString()) - 2);

        }
        if (cbo_Race.getSelectedItem().toString().equals("Half-Orc")) {
            spnr_Str.setValue(Integer.parseInt(spnr_Str.getValue().toString()) + 2);
            spnr_Cha.setValue(Integer.parseInt(spnr_Cha.getValue().toString()) - 2);
            spnr_Int.setValue(Integer.parseInt(spnr_Int.getValue().toString()) - 2);

        }
        if (cbo_Race.getSelectedItem().toString().equals("Gnome")) {
            spnr_Con.setValue(Integer.parseInt(spnr_Con.getValue().toString()) + 2);
            spnr_Str.setValue(Integer.parseInt(spnr_Str.getValue().toString()) - 2);


        }
    }

    public NPCEditBinding(String id) {
        this.cbo_Gender.addItem("Male");
        this.cbo_Gender.addItem("Female");

        this.cbo_Align.addItem("Lawful Good");
        this.cbo_Align.addItem("Chaotic Good");
        this.cbo_Align.addItem("Neutral Good");
        this.cbo_Align.addItem("Lawful Neutral");
        this.cbo_Align.addItem("True Neutral");
        this.cbo_Align.addItem("Chaotic Neutral");
        this.cbo_Align.addItem("Lawful Evil");
        this.cbo_Align.addItem("Neutral Evil");
        this.cbo_Align.addItem("Chaotic Evil");

        this.cbo_Race.addItem("Human");
        this.cbo_Race.addItem("Elf");
        this.cbo_Race.addItem("Half-Elf");
        this.cbo_Race.addItem("Dwarf");
        this.cbo_Race.addItem("Gnome");
        this.cbo_Race.addItem("Halfling");

        this.cbo_Class.addItem("Fighter");
        this.cbo_Class.addItem("Priest");
        this.cbo_Class.addItem("Rogue");
        this.cbo_Class.addItem("Sorcerer");
        this.cbo_Class.addItem("Mage");
        this.cbo_Class.addItem("Druid");
        this.cbo_Class.addItem("Ranger");

        //call the xml to populate the fields.
        File fileToBeParsed = new File("src/com/gryffonx/xml/npcs.xml");
        Document xmlDoc = null;
        SAXReader reader = new SAXReader();

        try {
            xmlDoc = reader.read(fileToBeParsed);
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        btn_OK.setText("Save");


        this.txt_Name.setText(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/name").getStringValue());
        this.spnr_Str.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/stats/strength").getStringValue()));
        this.txt_StrMod.setText(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/stats/strength/@str_mod").getStringValue());
        this.spnr_Dex.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/stats/dexterity").getStringValue()));
        this.spnr_Con.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/stats/constitution").getStringValue()));
        this.spnr_Int.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/stats/intelligence").getStringValue()));
        this.spnr_Wis.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/stats/wisdom").getStringValue()));
        this.spnr_Cha.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/stats/charisma").getStringValue()));

        spnr_levels1.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/classes/class/@class_level").getStringValue()));
        lbl_Levels1.setText(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/classes/class").getStringValue());
        cbo_Class.setSelectedItem(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/classes/class").getStringValue());
        if (cbo_Class.getSelectedItem().toString().equals("Priest")) {
            btn_Spells.setEnabled(true);
        }

        cbo_Gender.setSelectedItem(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/name/@gender").getStringValue());
        cbo_Align.setSelectedItem(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/alignment").getStringValue());
        cbo_Race.setSelectedItem(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/name/@race").getStringValue());

        spnr_Age.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/name/@age").getStringValue()));
        txt_hitPoints.setValue(new Integer(xmlDoc.selectSingleNode("npcs/npc[@npc_id='" + id + "']/hitpoints").getStringValue()));


        this.cbo_Class.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                lbl_Levels1.setText(cbo_Class.getSelectedItem().toString());

                if (cbo_Class.getSelectedItem().toString().equals("Sorcerer")
                        || cbo_Class.getSelectedItem().toString().equals("Priest")
                        || cbo_Class.getSelectedItem().toString().equals("Druid")
                        || cbo_Class.getSelectedItem().toString().equals("Ranger")
                        || cbo_Class.getSelectedItem().toString().equals("Mage")) {
                    btn_Spells.setEnabled(true);
                } else {
                    btn_Spells.setEnabled(false);
                }
            }
        });

        this.btn_Roll.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                rollStatsAndMods();
            }
        });

        this.btn_Money.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                NPCMoney window = new NPCMoney("Enter Quantity");
                window.pack();
                window.setVisible(true);

            }
        });

        this.btn_Spells.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                SpellList window = new SpellList("Choose Spells");
                window.pack();
                window.setVisible(true);

            }
        });
        this.btn_Cancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                pnl_MainPanel.getTopLevelAncestor().setVisible(false);
            }
        });

        this.btn_OK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                //save the changes to the xml file


            }
        });

    }

    private static void calculateMod(JSpinner basis, JTextField toChange) {
        String spnrValue = basis.getValue().toString();
        Integer spnrIntValue = new Integer(spnrValue);


        if (spnrIntValue < 0) {
            basis.setValue(new Integer("0"));
        }

        if (spnrIntValue == 0) {
            toChange.setText("-5");
        } else if (spnrIntValue == 1) {
            toChange.setText("-5");
        } else if (spnrIntValue == 2) {
            toChange.setText("-4");
        } else if (spnrIntValue == 3) {
            toChange.setText("-4");
        } else if (spnrIntValue == 4) {
            toChange.setText("-3");
        } else if (spnrIntValue == 5) {
            toChange.setText("-3");
        } else if (spnrIntValue == 6) {
            toChange.setText("-2");
        } else if (spnrIntValue == 7) {
            toChange.setText("-2");
        } else if (spnrIntValue == 8) {
            toChange.setText("-1");
        } else if (spnrIntValue == 9) {
            toChange.setText("-1");
        } else if (spnrIntValue == 10) {
            toChange.setText("");
        } else if (spnrIntValue == 11) {
            toChange.setText("");
        } else if (spnrIntValue == 12) {
            toChange.setText("");
        } else if (spnrIntValue == 13) {
            toChange.setText("");
        } else if (spnrIntValue == 14) {
            toChange.setText("+2");
        } else if (spnrIntValue == 15) {
            toChange.setText("+2");
        } else if (spnrIntValue == 16) {
            toChange.setText("+3");
        } else if (spnrIntValue == 17) {
            toChange.setText("+3");
        } else if (spnrIntValue == 18) {
            toChange.setText("+4");
        } else if (spnrIntValue == 19) {
            toChange.setText("+5");
        } else if (spnrIntValue == 20) {
            toChange.setText("+5");
        }

    }
}
